package com.fqh.service.impl;

import com.fqh.entity.Diningtable;
import com.fqh.entity.UserInfo;
import com.fqh.mapper.TableMapper;
import com.fqh.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Transactional
@Service
public class TableServiceImpl implements TableService {

    @Autowired
    private TableMapper tableMapper;

    public List<Diningtable> findAllTable() {
        return tableMapper.findAllTable();
    }

    public void updateTableState(String tableNum) throws Exception {
        tableMapper.updateTableState(tableNum);
    }

    public void addInfo(HttpServletRequest request, Integer loginId, Integer people, String tableNum) {
        UserInfo userInfo = new UserInfo();
        userInfo.setUser_id(loginId);
        userInfo.setTable_actualpeople(people);
        userInfo.setTable_id(tableNum);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String time = sdf.format(new Date().getTime());
        request.getSession().setAttribute("time", time);
        userInfo.setOrder_number(time);
        tableMapper.addInfo(userInfo);
    }

}
